# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Daniel M. Capella <polycitizen@gmail.com>
# Contributor: Bin Jin <bjin@ctrl-d.org>

pkgname=shaderc
pkgver=2023.5
pkgrel=1
pkgdesc='Collection of tools, libraries and tests for shader compilation'
url='https://github.com/google/shaderc'
arch=('loong64' 'x86_64')
license=('Apache')
depends=('glibc' 'gcc-libs' 'glslang' 'spirv-tools')
makedepends=('asciidoctor' 'cmake' 'ninja' 'python' 'spirv-headers')
provides=('libshaderc_shared.so')
source=(https://github.com/google/shaderc/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('acda1bb35a30f7f47aeb356c2b513a16161147130e8d6d939640b0f5646799a0a134c2846f197fdb9b4d93e8460bf715ed03f70d7e7daeeb16231d61f7a1382f')
b2sums=('79ad4c249f1bc543aca89633c5754148a8ae0806d1a51bfd1c3e40aa99bb341cc4b0ad4a095d1fc1389eac077c25db57e5a1221f81a0728981ad62601f26f297')

prepare() {
  cd ${pkgname}-${pkgver}

  # de-vendor libs and disable git versioning
  sed '/examples/d;/third_party/d' -i CMakeLists.txt
  sed '/build-version/d' -i glslc/CMakeLists.txt
  cat <<- EOF > glslc/src/build-version.inc
"${pkgver}\\n"
"$(pacman -Q spirv-tools|cut -d \  -f 2|sed 's/-.*//')\\n"
"$(pacman -Q glslang|cut -d \  -f 2|sed 's/-.*//')\\n"
EOF
}

build() {
  cd ${pkgname}-${pkgver}
  cmake \
    -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_CXX_FLAGS="$CXXFLAGS -ffat-lto-objects" \
    -DSHADERC_SKIP_TESTS=ON \
    -DSHADERC_ENABLE_WERROR_COMPILE=OFF \
    -Dglslang_SOURCE_DIR=/usr/include/glslang \
    -GNinja
  ninja -C build

  cd glslc
  asciidoctor -b manpage README.asciidoc -o glslc.1
}

check() {
  cd ${pkgname}-${pkgver}
  ninja -C build test
}

package() {
  cd ${pkgname}-${pkgver}
  DESTDIR="${pkgdir}" ninja -C build install
  install -Dm 644 glslc/glslc.1 -t "${pkgdir}/usr/share/man/man1"
}

# vim: ts=2 sw=2 et:
